﻿#region Header
// ------------------------ Licence / Copyright ------------------------
// 
// ScrumTable for Scrum Meeting Support
// Copyright © HSR - Hochschule für Technik Rapperswil
// All Rights Reserved
// 
// Author:
//  Michael Gfeller Silvan Gehrig Patrick Boos
// 
// ---------------------------------------------------------------------
#endregion

#region Usings

using System;
using System.Collections;
using System.Linq;
using ScrumTable.BL.DM.Properties;
using ScrumTable.Common;
using ScrumTable.Common.Collections;
using ScrumTable.DL.Data.Schema;
using System.Collections.Generic;

#endregion

namespace ScrumTable.BL.DM.DataManagement
{
    /// <summary>
    /// Defines a state work the scrum items. 
    /// If 2 states have the same id, they are equal.
    /// </summary>
    public class ScrumState
    {
        #region Declarations
        //--------------------------------------------------------------------
        // Declarations
        //--------------------------------------------------------------------

        #endregion

        #region Properties
        //--------------------------------------------------------------------
        // Properties
        //--------------------------------------------------------------------

        /// <summary>
        /// Contains the id. A same id means that the this states can be convertet into each other. Like resolved and verfiy
        /// </summary>
        public int Id { get; set; }

        /// <summary>
        /// name of the state
        /// </summary>
        public string Name { get; private set; }
        
        #endregion

        #region Constructors / Destructor
        //--------------------------------------------------------------------
        // Constructors / Destructor
        //--------------------------------------------------------------------

        private ScrumState()
        {
        }

        /// <summary>
        /// Creates a new ScrumState instance and initializes it by name and id.
        /// </summary>
        /// <param name="name">Specifies the name of the state.</param>
        /// <param name="id">Specifies the id and sort index of the state.</param>
        public ScrumState(string name, int id = -1)
        {
            PreCondition.AssertNotNull(name, "name");

            Name = name;
            Id = id;
        }

        #endregion

        #region Methods

        //--------------------------------------------------------------------
        // Methods
        //--------------------------------------------------------------------

        /// <summary>
        /// Returns a <see cref="T:System.String"/> that represents the current <see cref="T:System.Object"/>.
        /// </summary>
        /// <returns>
        /// A <see cref="T:System.String"/> that represents the current <see cref="T:System.Object"/>.
        /// </returns>
        /// <filterpriority>2</filterpriority>
        public override string ToString()
        {
            return Name;
        }

        /// <summary>
        /// Determines whether the specified <see cref="T:ScrumTable.BL.DM.DataManagement.ScrumState"/>
        /// is equal to the current <see cref="T:ScrumTable.BL.DM.DataManagement.ScrumState"/>.
        /// </summary>
        /// <returns>
        /// true if the specified <see cref="T:ScrumTable.BL.DM.DataManagement.ScrumState"/> is equal to
        /// the current <see cref="T:ScrumTable.BL.DM.DataManagement.ScrumState"/>; otherwise, false.
        /// </returns>
        /// <param name="other">The <see cref="T:ScrumTable.BL.DM.DataManagement.ScrumState"/> to compare with the current <see cref="T:System.Object"/>. </param>
        public bool Equals(ScrumState other)
        {
            if (ReferenceEquals(null, other)) return false;
            if (ReferenceEquals(this, other)) return true;
            return other.Id == Id;
        }

        /// <summary>
        /// Determines whether the specified <see cref="T:System.Object"/> is equal to the current <see cref="T:System.Object"/>.
        /// </summary>
        /// <returns>
        /// true if the specified <see cref="T:System.Object"/> is equal to the current <see cref="T:System.Object"/>; otherwise, false.
        /// </returns>
        /// <param name="obj">The <see cref="T:System.Object"/> to compare with the current <see cref="T:System.Object"/>. 
        ///                 </param><exception cref="T:System.NullReferenceException">The <paramref name="obj"/> parameter is null.
        ///                 </exception><filterpriority>2</filterpriority>
        public override bool Equals(object obj)
        {
            if (ReferenceEquals(null, obj)) return false;
            if (ReferenceEquals(this, obj)) return true;
            if (obj.GetType() != typeof(ScrumState)) return false;
            return Equals((ScrumState)obj);
        }

        /// <summary>
        /// Serves as a hash function for a particular type. 
        /// </summary>
        /// <returns>
        /// A hash code for the current <see cref="T:System.Object"/>.
        /// </returns>
        /// <filterpriority>2</filterpriority>
        public override int GetHashCode()
        {
            return Id;
        }

        /// <summary>
        /// Implements the operator ==.
        /// </summary>
        /// <param name="left">Specifies the left object.</param>
        /// <param name="right">Specifies the right object.</param>
        /// <returns>The result of the operator.</returns>
        public static bool operator ==(ScrumState left, ScrumState right)
        {
            return Equals(left, right);
        }

        /// <summary>
        /// Implements the operator !=.
        /// </summary>
        /// <param name="left">Specifies the left object.</param>
        /// <param name="right">Specifies the right object.</param>
        /// <returns>The result of the operator.</returns>
        public static bool operator !=(ScrumState left, ScrumState right)
        {
            return !Equals(left, right);
        }

        #endregion
    }
}